package com.pet.system.domain.dto;

import com.pet.system.domain.entity.SysRole;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 系统-角色 DTO 模型
 *
 * @author Centaurea
 */
@Getter
@Setter
@ToString
public class SysRoleDTO extends SysRole {
  /** 逗号分隔的资源ids */
  private String resourceIdStr;
  /** 资源ID集合 */
  private List<Integer> resourceIds;

  public List<Integer> getResourceIds() {
    if (resourceIds == null) {
      resourceIds = new ArrayList<>();
      for (String id : (null != resourceIdStr ? resourceIdStr : "").split(",")) {
        if (StringUtils.isEmpty(id)) {
          continue;
        }
        resourceIds.add(Integer.valueOf(id));
      }
    }
    return resourceIds;
  }
}
